#version 300 es
precision mediump float;
uniform sampler2D sTextureDay;
uniform sampler2D sTextureNight;
in float vFogFactor;
in vec4 vAmbient;
in vec4 vDiffuse;
in vec4 vSpecular;
in vec2 vTexCoors;

out vec4 fragColor ;

void main(){
    vec4 finalColorDay;
    vec4 finalColorNight;
    vec4 fogColor = vec4(0.97,0.76,0.03,1.0);

    finalColorDay= texture(sTextureDay, vTexCoors);
    finalColorDay = finalColorDay*vAmbient+finalColorDay*vSpecular+finalColorDay*vDiffuse;

    finalColorNight = texture(sTextureNight, vTexCoors);
    finalColorNight = finalColorNight*vec4(0.5,0.5,0.5,1.0);
    vec4 finalColor ;
    if(vDiffuse.x>0.21){
    finalColor=finalColorDay;
    }else if(vDiffuse.x<0.05){
    finalColor=finalColorNight;
    }else{
    float t=(vDiffuse.x-0.05)/0.16;
    finalColor=t*finalColorDay+(1.0-t)*finalColorNight;
    }

    if(vFogFactor != 0.0){
        fragColor = finalColor*vFogFactor + finalColor*(1.0-vFogFactor);
    }else{
        fragColor = finalColor ;
    }



}